#! /usr/bin/env python
#coding=GBK
import random,math,time
import iworld2d
import base_object
import t_const

inst = None
def init():
	global inst
	if not inst:
		inst = CCamera()

def destroy():
	global inst
	if inst:
		inst.destroy()
		inst = None

def update():
	if inst:
		inst.update()

#
class CCamera(base_object.CObject):
	def __init__(self):
		self.lock_on = False
		self.lock_obj = None

		pass

	def destroy(self):
		pass

	def set_lock_on(self, value = True, obj = None):
		self.lock_on = value
		self.lock_obj = obj
		pass

	def update_lock_on(self):
		if not self.lock_on:
			return
		pos = self.lock_obj.pos
		pos_x,pos_y = self.lock_obj.pos
		camera_x,camera_y = iworld2d.camera_to_worldpos(0,0)
		iworld2d.camera_world_pos(pos_x-512, 0)

	def update(self):
		self.update_lock_on()
		pass
